﻿using DevExpress.Persistent.BaseImpl;
using EasyXaf.EntityDesigner.Editors.LookupStringPropertyEditors;

namespace EasyXaf.EntityDesigner.BusinessObjects.Enums;

/// <summary>
/// 枚举
/// </summary>
public partial class Enumeration : BaseObject, IListBoxItemsProvider
{
    private partial string GetDisplayName()
    {
        if (!string.IsNullOrWhiteSpace(Caption))
        {
            return $"{Name}({Caption})";
        }
        return Name;
    }

    public string GetNamespace()
    {
        var @namespace = Namespace;
        if (string.IsNullOrWhiteSpace(@namespace))
        {
            @namespace = DomainModel.Namespace;
        }
        return @namespace;
    }

    public IEnumerable<string> GetListBoxItems(string targetMemberName)
    {
        if (targetMemberName == nameof(Namespace))
        {
            var namespaces = DomainModel.Entities.Select(e => e.Namespace).ToList();
            namespaces.AddRange(DomainModel.Enums.Select(e => e.Namespace));
            namespaces.Add(DomainModel.Namespace);
            return namespaces
                .Where(ns => !string.IsNullOrWhiteSpace(ns))
                .Distinct()
                .OrderBy(ns => ns);
        }
        return [];
    }
}
